using System;
using NUnit.Framework;
using Pine.Core;
using Pine.Compiler.Utils;

namespace UnitTests
{
	[TestFixture]
	public class TestLists
	{
		[Test]
		public void TestSwap() {
			ValueList rl = new ValueList();
			
			Compiler.ExecuteString("test-list-swap", "main", @"
			\main() {
				var a = 1; var b = 2;
				a, b = b, a;
				return a, b;
			}", rl, null);
			
			Assert.AreEqual(new Number(2), rl.GetArrayElement(0));
			Assert.AreEqual(new Number(1), rl.GetArrayElement(1));
		}
		
		[Test]
		public void TestReturnList() {
			ValueList rl = new ValueList();
			
			Compiler.ExecuteString("test-return-list", "main", @"
\foo() return 1, 2;

\main() {
	var a = 0;
	var b = 0;
	a, b = foo();
	return a + b;
}
", rl, null);
			
			Assert.AreEqual(new Number(3), rl.GetArrayElement(0));
		}
		
		[Test]
		public void TestListCompression() {
			ValueList rl = new ValueList();
			
			Compiler.ExecuteString("test-return-list", "main", @"
\foo() return 1, 2;

\main() {
	var a = 0;
	var b = 0;
	a, b = (x: 4, 0: 1, 2);
	return a, b;
}
", rl, null);
			
			Assert.AreEqual(new Number(1), rl.GetArrayElement(0));
			Assert.AreEqual(NullValue.Null, rl.GetArrayElement(1));
		}
	}
}

